package com.example.pair;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.MutablePair;

public class TestPair {

    /**
     * MutablePair
     *
     * @param user
     * @return
     */
    private static MutablePair<String, String> processUserInfo(User user) {
        return MutablePair.of(user.getId(), user.getName());
    }

    /**
     * ImmutablePair
     *
     * @param user
     * @return
     */
    private static ImmutablePair<String, String> processUserInfo1(User user) {
        return ImmutablePair.of(user.getId(), user.getName());
    }

    public static void main(String[] args) {
        User user = new User();
        user.setId("userId");
        user.setName("张三");

        MutablePair<String, String> mutablePair = processUserInfo(user);
        System.out.println(mutablePair.getLeft() + "------" + mutablePair.getRight());
        mutablePair.setLeft("userId2");
        System.out.println(mutablePair.getLeft() + "------" + mutablePair.getRight());
        System.out.println("------------------------------------------------");
        ImmutablePair<String, String> immutablePair = processUserInfo1(user);
        System.out.println(immutablePair.getLeft() + "------" + immutablePair.getRight());
        immutablePair.setValue("userId2");
        System.out.println(immutablePair.getLeft() + "------" + immutablePair.getRight());
    }
}
